<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
    <meta name="viewport" content="width=device-width, initial-scale=1.0">  

	{% load static %}
	<link rel="stylesheet" type="text/css" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.2/css/bootstrap.min.css" id="theme">
	<link rel="shortcut icon" href="{% static 'img/favicon.ico' %}">
	<style>
		    p img{
		        width: auto;
		        height: auto;
		        max-width: 100%;
		        display: block;
		    }
			.ql-editor {
				min-height: 50vh;
				max-height: 80vh;
				min-width: 120vh;
				overflow: auto;
			}
	</style>
	{{ form.media }}  <!-- django-quill-editor 自动加载资源 -->
	<title>{% block title %}{% endblock %}</title>
</head>
<body>
	<nav class="navbar navbar-expand-sm bg-light navbar-light" role="navigation" id="nav-sp">
		<div class="container">
			<div class="navbar-header">
				<a href="{% url 'home:index' %}" class="navbar-brand">博雅同学录</a>
			</div>

			<button class="navbar-toggler" data-toggle="collapse" data-target="#table-nav">
             	<span class="navbar-toggler-icon"></span>
         	</button>

			<div class="collapse navbar-collapse" id="table-nav">
				<ul class="navbar-nav">
					<li class="nav-item"><a class="nav-link" href="{% url 'home:index' %}">首页</a></li>
					<li class="nav-item"><a class="nav-link" href="{% url 'teacher:index' %}">有关老师</a></li>
					<li class="nav-item"><a class="nav-link" href="{% url 'student:index' %}">有关同学</a></li>
					<li class="nav-item"><a class="nav-link" href="{% url 'events:index' %}">班级大事记</a></li>
					<li class="nav-item"><a class="nav-link" href="{% url 'message:index' %}">留言墙</a></li>
				</ul>
				<ul class="navbar-nav ml-auto">
					<li class="dropdown">
						<a href="#" class="dropdown-toggle nav-link" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">主题<span class="caret"></span></a>
						<ul class="dropdown-menu">
						  	<li><a class="dropdown-item nav-link" href="#" id="default-theme">Default</a></li>
						  	<li><a class="dropdown-item nav-link" href="#" id="cyborg-theme">Cyborg</a></li>
							<li><a class="dropdown-item nav-link" href="#" id="superhero-theme">SuperHero</a></li>
							<li><a class="dropdown-item nav-link" href="#" id="journal-theme">Journal</a></li>
							<li><a class="dropdown-item nav-link" href="#" id="minty-theme">Minty</a></li>
							<li><a class="dropdown-item nav-link" href="#" id="sketchy-theme">Sketchy</a></li>
							<li><a class="dropdown-item nav-link" href="#" id="lux-theme">Lux</a></li>
						</ul>
					</li>
					<li class="dropdown">
						<a href="#" class="dropdown-toggle nav-link" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">账户<span class="caret"></span></a>
						<ul class="dropdown-menu">
						  	{% if request.user.is_authenticated %}
						  	<li class="dropdown-item">欢迎 {{ request.user.username }}</li>
	                        {% if request.user.is_superuser %}
	                        <li><a class="dropdown-item nav-link" href="/admin" id="default-theme">管理面板</a></li>
	                        {% endif %}
	        
						  	<li><a class="dropdown-item nav-link" href="{% url 'login:logouts' %}" id="default-theme">登出</a></li>
						  	<li><a class="dropdown-item nav-link" href="{% url 'login:rename' %}" id="default-theme">改名</a></li>
						  	{% else %}
						  	<li class="dropdown-item">您尚未登录！</li>
						  	<li><a class="dropdown-item nav-link" href="{% url 'login:register' %}" id="default-theme">注册</a></li>
						  	<li><a class="dropdown-item nav-link" href="{% url 'login:login' %}" id="default-theme">登录</a></li>
						  	{% endif %}
						</ul>
					</li>
					<li class="nav-item"><a class="nav-link" href="{% url 'feedback:index' %}">反馈</a></li>
					<li class="nav-item"><a class="nav-link" href="{% url 'about:index' %}">有关作者</a></li>
				</ul>
			</div>
		</div>
	</nav>
	{% block content %}{% endblock %}
	<div class="container">
		<hr/>
		<footer>
			<p>2025 Copyright 温子豪<a href="https://beian.miit.gov.cn/" target="_blank">nope</a></p>
		</footer>
	</div>
	
	<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js" type="text/javascript"></script>
	<script>
		function getCookie(cname)
		{
			var name = cname + "=";
			var ca = document.cookie.split(';');
			for (var i = 0; i < ca.length; i++) 
			{
				var c = ca[i].trim();
				if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
			}
			return "";
		}

		function setCookie(cname,cvalue,exdays)
		{
			var d = new Date();
			d.setTime(d.getTime()+(exdays*24*60*60*1000));
			var expires = "expires="+d.toGMTString();
			document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
		}

		function ajax_theme() // 查询主题
		{
			$.ajax({
				url: '/theme_settings/',
				type: 'get',
				async: false,
				success: function (arg) 
				{
					data = JSON.parse(arg);
					if (data['user'] == 'yes')
					{
						setCookie('theme', data['theme'], 10000000);
					}
				}
			});
		}

		function ajax_theme_write(theme_name) // 修改主题
		{
			$.ajax({
				url: '/theme_write/',
				type: 'post',
				data: {'theme': theme_name},
				async: false,
				headers: {"X-CSRFToken": "{{ csrf_token }}"},
				success: function (arg)
				{
					data = JSON.parse(arg);
					// console.log(data['ok'] + ' write1');
				}
			});
			setCookie('theme', theme_name, 60*60*24*30);
		}

		function theme(theme_name)
		{
			var obj = document.getElementById("theme");
			if (theme_name == 'default')
			{
				obj.setAttribute("href", "https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.2/css/bootstrap.min.css");
				document.getElementById("nav-sp").className = "navbar navbar-expand-sm bg-light navbar-light";
			}
			else if (theme_name == 'cyborg' || theme_name == 'superhero')
			{
				obj.setAttribute("href", "https://cdn.bootcdn.net/ajax/libs/bootswatch/4.6.2/" + theme_name + "/bootstrap.min.css");
				document.getElementById("nav-sp").className = "navbar navbar-expand-sm bg-dark navbar-dark";
			}
			else
			{
				obj.setAttribute("href", "https://cdn.bootcdn.net/ajax/libs/bootswatch/4.6.2/" + theme_name + "/bootstrap.min.css");
				document.getElementById("nav-sp").className = "navbar navbar-expand-sm bg-light navbar-light";
			}
			ajax_theme_write(theme_name);
		}

		function theme_cookie()
		{
			if (getCookie('theme') != '')
			{
				theme(getCookie('theme'));
			}
			else
			{
				theme('default');
			}
		}

		ajax_theme();
		theme_cookie();
		document.getElementById('cyborg-theme').addEventListener('click', function() 
		{
			theme('cyborg');
		});
		document.getElementById('default-theme').addEventListener('click', function() 
		{
			theme('default');
		});
		document.getElementById('superhero-theme').addEventListener('click', function() 
		{
			theme('superhero');
		});
		document.getElementById('journal-theme').addEventListener('click', function() 
		{
			theme('journal');
		});
		document.getElementById('minty-theme').addEventListener('click', function() 
		{
			theme('minty');
		});
		document.getElementById('sketchy-theme').addEventListener('click', function() 
		{
			theme('sketchy');
		});
		document.getElementById('lux-theme').addEventListener('click', function() 
		{
			theme('lux');
		});
	</script>
	<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.2/js/bootstrap.min.js"></script>
</body>
</html>
